{php include wl_template('common/header');}
<ul class="nav nav-tabs">


    <li {if  $op == 'display'} class="active"{/if}>
    <a href="{php echo web_url('goods/saler/display')}">老师管理</a>
    </li>
    {if $op == 'post' }
    <li {if  $op == 'post'} class="active"{/if}>
    <a href="{php echo web_url('goods/saler',array('op'=>'post'))}">编辑老师</a>
    </li>
   {/if}
    <!--<li class="ex-button"><a class="ex-b-lastA" target="_blank" href="http://v.youku.com/v_show/id_XMTc0OTkxODE0OA==.html?from=s1.8-1-1.2&spm=a2h0k.8191407.0.0">视频演示</a></li>-->
    <!--<li class="ex-button"><a target="_blank" href="http://doc.lexiangpingou.cn/packBySelf.html">图文说明</a></li>-->
</ul>

{if $op == 'post'}
<div class="main">
    <form action="" method="post" class="form-horizontal form" enctype="multipart/form-data">
        <div class='panel panel-default'>
            <div class='panel-heading'>
                编辑
            </div> 
           
            <div class="form-group">
                <label class="col-xs-12 col-sm-3 col-md-2 control-label"><span style='color:red'>*</span> 选择老师</label>
                <div class="col-sm-9 col-xs-12">
                    <input type='hidden' id='openid' name='openid' value="{$saler['openid']}" />
                    <div class='input-group'>
                        <input type="text" name="saler2" maxlength="30" value="{if !empty($saler)}{$saler['nickname']}{/if}" id="saler2" class="form-control" readonly />
                        <div class='input-group-btn'>
                            <button class="btn btn-default" type="button" onclick="popwin = $('#modal-module-menus').modal();">选择老师</button>
                        </div>
                    </div>
                    {if !empty($saler)}
                    <span class='help-block'><img style="width:100px;height:100px;border:1px solid #ccc;padding:1px" src="{$saler['avatar']}" id="avatar" /></span>
                    {/if}
                    <div id="modal-module-menus"  class="modal fade" tabindex="-1">
                        <div class="modal-dialog" style='width: 660px;'>
                            <div class="modal-content">
                                <div class="modal-header"><button aria-hidden="true" data-dismiss="modal" class="close" type="button">×</button><h3>选择老师</h3></div>
                                <div class="modal-body" >
                                    <div class="row">
                                        <div class="input-group">
                                            <input type="text" class="form-control" name="keyword" value="" id="search-kwd" placeholder="请输入粉丝昵称" />
                                            <span class='input-group-btn'><button type="button" class="btn btn-default" onclick="search_members();">搜索</button></span>
                                        </div>
                                    </div>
                                    <div id="module-menus" style="padding-top:5px;"></div>
                                </div>
                                <div class="modal-footer"><a href="#" class="btn btn-default" data-dismiss="modal" aria-hidden="true">关闭</a></div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
            <div class="form-group" style="display: none">
                <label class="col-xs-12 col-sm-3 col-md-2 control-label"><span style='color:red'>*</span>老师风采</label>
                <div class="col-sm-6">
                    {php echo tpl_form_field_multi_image('img',$piclist);}
                    <span class="help-block">老师详情，建议640X350</span>
                </div>
            </div>
            <div class="form-group" style="display: none">
                <label class="col-xs-12 col-sm-3 col-md-2 control-label">性别</label>
                <div class="col-sm-9 col-xs-12">
                    <label class='radio-inline'>
                        <input type='radio' name='sex' value='男' {if $saler['sex']=='男'}checked{/if} /> 男
                    </label>
                    <label class='radio-inline'>
                        <input type='radio' name='sex' value='女' {if $saler['sex']=='女'}checked{/if} /> 女
                    </label>
                </div>
            </div>
            <div class="form-group" style="display: none">
                <label class="col-xs-12 col-sm-3 col-md-2 control-label">客服（美洽ID）</label>
                <div class="col-sm-9 col-xs-12">
                    <input type="text" name="kefu" value="{$saler['kefu']}" />
                </div>
            </div>
            <div class="form-group" style="display: none">
                <label class="col-xs-12 col-sm-3 col-md-2 control-label">联系电话</label>
                <div class="col-sm-9 col-xs-12">
                    <input type="text" name="mobile" value="{$saler['mobile']}" />
                </div>
            </div>
            <div class="form-group">
                <label class="col-xs-12 col-sm-3 col-md-2 control-label"><span style='color:red'>*</span>核销门店选择</label>
                <div class="col-sm-9 col-xs-12 chks">
                    <div class='input-group'>
                        <input type="text" name="saler" maxlength="30" value="{loop $salers $item} {$item['nickname']}; {/loop}" id="saler" class="form-control" readonly />
                        <div class='input-group-btn'>
                            <button class="btn btn-default" type="button" onclick="popwin = $('#modal-module-menus2').modal();">选择门店</button>
                        </div>
                    </div>

                    <div style="margin-top:.5em;" class="input-group multi-audio-details clear-fix" id='stores'>
                        {loop $stores $store}
                        <div style="height: 40px; position:relative; float: left; margin-right: 18px;" class="multi-audio-item" storeid="{$store['goods_id']}">
                            <div class="input-group">
                                <input type="hidden" value="{$store['id']}" name="storeids[]">
                                <input type="text" value="{$store['storename']}" readonly="" class="form-control">
                                <div class="input-group-btn">
                                    <button type="button" onclick="remove_store(this)" class="btn btn-default"><i class="fa fa-remove"></i></button>
                                </div>
                            </div>
                        </div>
                        {/loop}
                    </div>
                   
                    <div id="modal-module-menus2" class="modal fade" tabindex="-1">
                        <div class="modal-dialog" style='width: 660px;'>
                            <div class="modal-content">
                                <div class="modal-header">
                                    <button aria-hidden="true" data-dismiss="modal" class="close" type="button">×</button>
                                    <h3>选择门店</h3></div>
                                <div class="modal-body">
                                    <div class="row">
                                        <div class="input-group">
                                            <input type="text" class="form-control" name="keyword" value="" id="search-kwd2" placeholder="请输入门店名称" />
                                            <span class='input-group-btn'><button type="button" class="btn btn-default" onclick="search_stores();">搜索</button></span>
                                        </div>
                                    </div>
                                    <div id="module-menus2" style="padding-top:5px;"></div>
                                </div>
                                <div class="modal-footer"><a href="#" class="btn btn-default" data-dismiss="modal" aria-hidden="true">关闭</a></div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>

            <div class="form-group" {if $_W['uniacid'] == 6}style="display: none"{/if}>
                <label class="col-xs-12 col-sm-3 col-md-2 control-label"><span style='color:red'>*</span>项目选择</label>
                <div class="col-sm-9 col-xs-12 chks">
                    <div class='input-group'>
                        <input type="text" name="saler3" maxlength="30" value="" id="saler3" class="form-control" readonly />
                        <div class='input-group-btn'>
                            <button class="btn btn-default" type="button" onclick="popwin = $('#modal-module-menus3').modal();">选择项目(不选默认为全部项目核销)</button>
                        </div>
                    </div>

                    <div style="margin-top:.5em;" class="input-group multi-audio-details clear-fix" id='stores3'>
                        {loop $xiangmus $store}
                        <div style="height: 40px; position:relative; float: left; margin-right: 18px;" class="multi-audio-item" xmid="{$store['goods_id']}">
                            <div class="input-group">
                                <input type="hidden" value="{$store['goods_id']}" name="xiangmuids[]">
                                <input type="text" value="{$store['goodsname']}" readonly="" class="form-control">
                                <div class="input-group-btn">
                                    <button type="button" onclick="remove_xiangmu(this)" class="btn btn-default"><i class="fa fa-remove"></i></button>
                                </div>
                            </div>
                        </div>
                        {/loop}
                    </div>

                    <div id="modal-module-menus3" class="modal fade" tabindex="-1">
                        <div class="modal-dialog" style='width: 660px;'>
                            <div class="modal-content">
                                <div class="modal-header">
                                    <button aria-hidden="true" data-dismiss="modal" class="close" type="button">×</button>
                                    <h3>选择项目</h3></div>
                                <div class="modal-body">
                                    <div class="row">
                                        <div class="input-group">
                                            <input type="text" class="form-control" name="keyword" value="" id="search-kwd3" placeholder="请输入项目名称" />
                                            <span class='input-group-btn'><button type="button" class="btn btn-default" onclick="search_xiangmu();">搜索</button></span>
                                        </div>
                                    </div>
                                    <div id="module-menus3" style="padding-top:5px;"></div>
                                </div>
                                <div class="modal-footer"><a href="#" class="btn btn-default" data-dismiss="modal" aria-hidden="true">关闭</a></div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>

            <div class="form-group" style="display: none">
                <label class="col-xs-12 col-sm-3 col-md-2 control-label">简介</label>
                <div class="col-sm-9 col-xs-12">
                    <textarea class="form-control" name="content" rows="3">{$saler['content']}</textarea>
                </div>
            </div>

            <div class="form-group">
                <label class="col-xs-12 col-sm-3 col-md-2 control-label">状态</label>
                <div class="col-sm-9 col-xs-12">
                    <label class='radio-inline'>
                        <input type='radio' name='salerstatus' value=1 {if $saler['status']==1}checked{/if} /> 启用
                    </label>
                    <label class='radio-inline'>
                        <input type='radio' name='salerstatus' value=0 {if $saler['status']==0}checked{/if} /> 禁用
                    </label>
                </div>
            </div>

            <div class="form-group"></div>
            <div class="form-group">
                <label class="col-xs-12 col-sm-3 col-md-2 control-label"></label>
                <div class="col-sm-9 col-xs-12">
                    <input type="hidden" name="salerid" value="{$id}" />
                    <input type="hidden" name="op" value="{$op}" />
                    <input type="submit" name="salersubmit" value="提交" class="btn btn-primary col-lg-1"  />
                    <input type="hidden" name="token" value="{$_W['token']}" />
                </div>
            </div>
        </div>
</div>
</form>
</div>
<script language='javascript'>
    $('form').submit(function () {
        if ($(':input[name=saler2]').val()=='') {
            util.message('请选择老师');
//            Tip.focus($(':input[name=saler2]'), '请选择老师!');
            return false;
        }
        if ($('#stores').html()=='') {
            util.message('请选择门店');
//            Tip.focus($(':input[name=saler]'), '请选择门店!');
            return false;
        }
        console.log($(this).html());
//        if ($('#stores3').html()=='') {
//            util.message('请选择项目');
////            Tip.focus($(':input[name=saler3]'), '请选择项目!');
//            return false;
//        }
        return true;
    })
</script>
{elseif $op == 'display'}
<form action="" method="post" onsubmit="return formcheck(this)">
    <div class='panel panel-default'>
        <div class='panel-heading'>
           老师管理
        </div>
        <div class='panel-body'>
            <table class="table">
                <thead>
                <tr>
                    <!-- 	<th>所属商家</th>-->
                    <th>老师名称</th>
                    <th>所属门店</th>
                    <th>状态</th>
                    <th>操作</th>
                </tr>
                </thead>
                <tbody>
                {loop $list $row}
                <tr>
                    <!--	<td>{if $row['merchant']['name']}{$row['merchant']['name']}{else}{$_W['account']['name']}{/if}</td>-->
                    <td style="text-align:left;"><img src="{$row['avatar']}" style="width:30px;height:30px;padding1px;border:1px solid #ccc" id="avatar" /> {$row['nickname']}</td>
                    <td>{if empty($row['storename'])}全店核销{else}{$row['storename']}{/if}</td>
                    <td>
                        {if $row['status']==1}
                        <span class='label label-success'>启用</span>
                        {else}
                        <span class='label label-danger'>禁用</span>
                        {/if}
                    </td>
                    <td>
                        <a class='btn btn-default' href="{php echo web_url('goods/saler', array('op'=>'post','id' => $row['id']))}"><i class='fa fa-edit'></i></a>
                        <a class='btn btn-default'  href="{php echo web_url('goods/saler', array('op'=>'delete', 'id' => $row['id']))}" onclick="return confirm('确认删除此老师吗？');
		                                    return false;"><i class='fa fa-remove'></i></a>
                    </td>
                </tr>
                {/loop}
                </tbody>
            </table>
        </div>
        <div class='panel-footer'>
            <a class='btn btn-default' href="{php echo web_url('goods/saler', array('op'=>'post'))}"><i class="fa fa-plus"></i> 添加新老师</a>
        </div>
    </div>
</form>
{/if}

<script language='javascript'>

    function search_members() {
        if( $.trim($('#search-kwd').val())==''){
            Tip.focus('#search-kwd','请输入关键词');
            return;
        }

        $("#module-menus").html("正在搜索....")
        $.get('{php echo web_url('goods/bdelete/display',array('op'=>'selectsaler'))}', {
            keyword: $.trim($('#search-kwd').val())
        }, function(dat){
            $('#module-menus').html(dat);
        });
    }
    function select_member(o) {
        $("#openid").val(o.openid);
        $("#saler2").val(o.nickname);
        $("#avatar").attr('src', o.avatar);
        $(".close").click();
    }
    function search_stores() {
        $("#module-menus2").html("正在搜索....")
        $.get('{php echo web_url('goods/bdelete/display',array('op'=>'selectstore'))}', {
            keyword: $.trim($('#search-kwd2').val())
        }, function(dat){
            $('#module-menus2').html(dat);
        });
    }
    function search_xiangmu() {
        $("#module-menus3").html("正在搜索....")
        $.get('{php echo web_url('goods/bdelete/display',array('op'=>'selectgoods'))}', {
            keyword: $.trim($('#search-kwd3').val())
        }, function(dat){
            $('#module-menus3').html(dat);
        });
    }
    function remove_store(obj){
        var storeid = $(obj).closest('.multi-audio-item').attr('storeid');
        $('.multi-audio-item[storeid="' + storeid +'"]').remove();
        // if(!$('.multi-audio-item').attr('storeid')){ 
        //     $('input[name="saler3"]').val(''); 
        // }
    }
    function remove_xiangmu(obj){
        var storeid = $(obj).closest('.multi-audio-item').attr('xmid');
        $('.multi-audio-item[xmid="' + storeid +'"]').remove();
        // if(!$('.multi-audio-item').attr('xmid')) {
        //     $('.multi-audio-details').remove();
        //     $('input[name="saler3"]').removeAttr('value'); 
        // }
    }
    function select_store(o) {
        if($('.multi-audio-item[storeid="' + o.id +'"]').length>0){
            return;
        }
        var html ='<div style="height: 40px; position:relative; float: left; margin-right: 18px;" class="multi-audio-item" storeid="' + o.id +'">';
        html+='<div class="input-group">';
        html+='<input type="hidden" value="' + o.id +'" name="storeids[]">';
        html+='<input type="text" value="' + o.storename +'" readonly="" class="form-control">';
        html+='<div class="input-group-btn"><button type="button" onclick="remove_store(this)" class="btn btn-default"><i class="fa fa-remove"></i></button></div>';
        html+='</div></div>';
        $('#stores').html(html);
    }
    function select_xiangmu(o) {
        if($('.multi-audio-item[storeid="' + o.id +'"]').length>0){
            return;
        }
        var html ='<div style="height: 40px; position:relative; float: left; margin-right: 18px;" class="multi-audio-item" storeid="' + o.id +'">';
        html+='<div class="input-group">';
        html+='<input type="hidden" value="' + o.id +'" name="xiangmuids[]">';
        html+='<input type="text" value="' + o.gname +'" readonly="" class="form-control">';
        html+='<div class="input-group-btn"><button type="button" onclick="remove_store(this)" class="btn btn-default"><i class="fa fa-remove"></i></button></div>';
        html+='</div></div>';
        $('#stores3').append(html);
    }
</script>

{php include wl_template('common/footer');}